<!-- HTML header for doxygen 1.8.13-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link rel="icon" type="image/x-icon" href="favicon.ico" />
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.13"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>chigraph: SubprocessExample.cpp</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
</script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectlogo"><img alt="Logo" src="chigraphDoxygenIcon.png"/></td>
  <td id="projectalign" style="padding-left: 0.5em;">
   <div id="projectname">chigraph
   &#160;<span id="projectnumber">master</span>
   </div>
   <div id="projectbrief">Systems programming language written for beginners in LLVM</div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.13 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
$(function() {
  initMenu('',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
</script>
<div id="main-nav"></div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
      <div id="nav-sync" class="sync"></div>
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
$(document).ready(function(){initNavTree('SubprocessExample_8cpp-example.html','');});
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div class="header">
  <div class="headertitle">
<div class="title">SubprocessExample.cpp</div>  </div>
</div><!--header-->
<div class="contents">
<div class="fragment"><div class="line"></div><div class="line"><span class="preprocessor">#include &lt;chi/Subprocess.hpp&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;chi/Result.hpp&gt;</span></div><div class="line"></div><div class="line"><span class="preprocessor">#include &lt;iostream&gt;</span></div><div class="line"></div><div class="line"><span class="keywordtype">int</span> main() {</div><div class="line">    </div><div class="line">    <a name="_a0"></a><a class="code" href="structchi_1_1Subprocess.html">chi::Subprocess</a> child{</div><div class="line"><span class="preprocessor">#ifdef WIN32</span></div><div class="line">        <span class="stringliteral">&quot;C:\\Windows\\System32\\cmd.exe&quot;</span></div><div class="line"><span class="preprocessor">#else</span></div><div class="line">        <span class="stringliteral">&quot;/bin/sh&quot;</span></div><div class="line"><span class="preprocessor">#endif</span></div><div class="line">    };</div><div class="line">    </div><div class="line">    std::string stdOut;</div><div class="line">    child.<a name="a1"></a><a class="code" href="structchi_1_1Subprocess.html#a1b08709bbb208a970888ebcccc58906c">attachStringToStdOut</a>(stdOut);</div><div class="line">    </div><div class="line">    <a name="_a2"></a><a class="code" href="structchi_1_1Result.html">chi::Result</a> res;</div><div class="line">    res += child.start();</div><div class="line">    <span class="keywordflow">if</span> (!res) {</div><div class="line">        std::cerr &lt;&lt; res &lt;&lt; std::endl;</div><div class="line">        <span class="keywordflow">return</span> 1;</div><div class="line">    }</div><div class="line">    </div><div class="line">    std::string dataToSend = <span class="stringliteral">&quot;echo hello&quot;</span>;</div><div class="line">    res += child.pushToStdIn(dataToSend.data(), dataToSend.size());</div><div class="line">    <span class="keywordflow">if</span> (!res) {</div><div class="line">        std::cerr &lt;&lt; res &lt;&lt; std::endl;</div><div class="line">        <span class="keywordflow">return</span> 1;</div><div class="line">    }</div><div class="line">    res += child.closeStdIn();</div><div class="line">    <span class="keywordflow">if</span> (!res) {</div><div class="line">        std::cerr &lt;&lt; res &lt;&lt; std::endl;</div><div class="line">        <span class="keywordflow">return</span> 1;</div><div class="line">    }</div><div class="line">    </div><div class="line">    <span class="keywordtype">int</span> exitCode = child.exitCode();</div><div class="line">    <span class="keywordflow">if</span> (exitCode != 0) {</div><div class="line">        std::cerr &lt;&lt; <span class="stringliteral">&quot;Failed run /bin/sh &lt; &#39;echo hi&#39; with exit code: &quot;</span> &lt;&lt; exitCode &lt;&lt; std::endl;</div><div class="line">        <span class="keywordflow">return</span> 1;</div><div class="line">    }</div><div class="line">    </div><div class="line">    std::cout &lt;&lt; stdOut &lt;&lt; std::endl;</div><div class="line">}</div></div><!-- fragment --> </div><!-- contents -->
</div><!-- doc-content -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
  <ul>
    <li class="footer">Generated on Sat Sep 16 2017 17:41:35 for chigraph by
    <a href="http://www.doxygen.org/index.html">
    <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.8.13 </li>
  </ul>
</div>
</body>
</html>
